class Food {
    constructor(cellSize) {
        this.radius = 5;
        this.cellSize = cellSize;
        this.respawn(500, 500); // 初始随机位置
    }

    respawn(canvasWidth, canvasHeight) {
        // 计算网格数量
        const gridWidth = Math.floor(canvasWidth / this.cellSize);
        const gridHeight = Math.floor(canvasHeight / this.cellSize);
        
        // 随机选择一个格子
        const gridX = Math.floor(Math.random() * gridWidth);
        const gridY = Math.floor(Math.random() * gridHeight);
        
        // 将食物放在格子中心
        this.x = gridX * this.cellSize + this.cellSize / 2;
        this.y = gridY * this.cellSize + this.cellSize / 2;
    }

    draw(ctx) {
        ctx.beginPath();
        ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
        ctx.fillStyle = '#00FF00';
        ctx.fill();
        ctx.closePath();
    }
} 